home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / STRCATM.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  126 lines

  1. StdGrp        group    StdLib, StdData
  2. ;
  3. StdData        segment    para public 'sldata'
  4.         public    sl_strcatm
  5. ;
  6. scptr1        dd    ?
  7. strlen1        dw    ?
  8. scptr2        dd    ?
  9. strlen2        dw    ?
  10. ;
  11. StdData        ends
  12. ;
  13. stdlib        segment    para public 'slcode'
  14.         assume    cs:StdGrp
  15. ;
  16.         extrn    sl_malloc:far
  17. ;
  18. ; strcatm-Computes the lengths of two strings pointed at by es:di and dx:si
  19. ;      then allocates storage for a string long enough to hold the con-
  20. ;      catentation of these two strings.  Finally, it concatenates the
  21. ;      two strings storing the resulting string into the new buffer.
  22. ;      Returns ED:SI pointing at the new string.
  23. ;
  24. ; inputs:
  25. ;
  26. ;    ES:DI- Points at the first string.
  27. ;
  28. ;    DX:SI- Points at the string to append.
  29. ;
  30. ;
  31. ; outputs:
  32. ;
  33. ;    ES:DI- Points at new string containing the concatenation of the
  34. ;           two strings.
  35. ;
  36. ;    carry=0 if no error.
  37. ;    carry=1 if strcat2 could not allocate enough memory to hold
  38. ;        the resulting string.
  39. ;
  40. sl_strcatm    proc    far
  41.         push    ds
  42.         push    si
  43.         push    cx
  44.         push    ax
  45.         pushf
  46.         cld
  47. ;
  48. ; Save pointers to the strings
  49. ;
  50.         mov    word ptr StdGrp:scptr1, di
  51.         mov    word ptr StdGrp:scptr1+2, es
  52.         mov    word ptr StdGrp:scptr2, si
  53.         mov    word ptr StdGrp:scptr2+2, dx
  54. ;
  55. ; Compute the length of the second string.
  56. ;
  57.         mov    al, 0
  58.         les    di, StdGrp:scptr2
  59.         mov    cx, 0ffffh
  60.     repne    scasb
  61.         neg    cx
  62.         dec    cx
  63.         mov    StdGrp:StrLen2, cx
  64. ;
  65. ; Find the end of the first string:
  66. ;
  67.         les    di, StdGrp:scptr1
  68.         mov    cx, 0ffffh
  69.     repne    scasb
  70.         neg    cx
  71.         dec    cx
  72.         dec    cx
  73.         mov    StdGrp:StrLen1, cx
  74. ;
  75. ; Malloc the appropriate storage:
  76. ;
  77.         add    cx, StdGrp:StrLen2
  78.         call    sl_malloc
  79.         jc    BadStrCat2
  80. ;
  81. ; Save ptr to dest
  82. ;
  83.         push    es
  84.         push    di        
  85. ;
  86. ; Copy the strings:
  87. ;
  88.         lds    si, StdGrp:scptr1
  89.         mov    cx, StdGrp:strlen1
  90.         shr    cx, 1
  91.         jnc    cs1
  92.         lodsb
  93.         stosb
  94. cs1:    rep    movsw
  95.         lds    si, StdGrp:scptr2
  96.         mov    cx, StdGrp:strlen2
  97.         shr    cx, 1
  98.         jnc    cs2
  99.         lodsb
  100.         stosb
  101. cs2:    rep    movsw
  102. ;
  103.         pop    di
  104.         pop    es
  105.         popf
  106.         pop    ax
  107.         pop    cx
  108.         pop    si
  109.         pop    ds
  110.         clc
  111.         ret
  112. ;
  113. BadStrCat2:    les    di, StdGrp:scptr1
  114.         popf
  115.         pop    ax
  116.         pop    cx
  117.         pop    si
  118.         pop    ds
  119.         stc
  120.         ret
  121. sl_strcatm    endp
  122. ;
  123. ;
  124. stdlib        ends
  125.         end
  126.